<?php
App::uses('AppController', 'Controller');
/**
 * Parametros Controller
 *
 * @property Parametro $Parametro
 * @property PaginatorComponent $Paginator
 */
class ParametrosController extends AppController {

/**
 * Components
 *
 * @var array
 */
	public $components = array('Paginator');
    public $uses = array('Parametro');
    public $layout = 'sib';

/**
 * index method
 *
 * @return void
 */
	public function index() {
		$this->Parametro->recursive = 0;
		$this->set('parametros', $this->Paginator->paginate());
	}

/**
 * view method
 *
 * @throws NotFoundException
 * @param string $id
 * @return void
 */
	public function view($id = null) {
		if (!$this->Parametro->exists($id)) {
			throw new NotFoundException(__('Invalid parametro'));
		}
		$options = array('conditions' => array('Parametro.' . $this->Parametro->primaryKey => $id));
		$this->set('parametro', $this->Parametro->find('first', $options));
	}

/**
 * add method
 *
 * @return void
 */
	public function parametro($idParametro = null) {
            if (!empty($this->request->data))
            {
                $this->Parametro->create();
                if ($this->Parametro->save($this->data))
                {
                    $this->Session->setFlash('Parametro registrado con exito', 'msgbueno');
                    $this->redirect(array('action' => 'index'), null, true);
                } else
                {
                    $this->Session->setFlash('No se pudo registrar el Parametro','msgerror');
                    $this->redirect(array('action' => 'index'));
                }
            }
            else{
                $this->Parametro->id = $idParametro;
                $this->request->data = $this->Parametro->read();
            }
	}

/**
 * edit method
 *
 * @throws NotFoundException
 * @param string $id
 * @return void
 */
	public function edit($id = null) {
		if (!$this->Parametro->exists($id)) {
			throw new NotFoundException(__('Invalid parametro'));
		}
		if ($this->request->is(array('post', 'put'))) {
			if ($this->Parametro->save($this->request->data)) {
				$this->Session->setFlash(__('The parametro has been saved.'));
				return $this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The parametro could not be saved. Please, try again.'));
			}
		} else {
			$this->Parametro->id=$id;
			$this->request->data = $this->Parametro->read();
                        //debug($this->request->data); exit;
		}
	}

/**
 * delete method
 *
 * @throws NotFoundException
 * @param string $id
 * @return void
 */
    public function delete($id = null)
    {
        $this->Parametro->id = $id;
        $this->request->data = $this->Parametro->read();
        if (!$id)
        {
            $this->Session->setFlash('No existe el Parametro a Eliminar');
            $this->redirect(array('action' => 'index'));
        } else
        {
            if ($this->Parametro->delete($id))
            {
                $this->Session->setFlash('Se elimino el Parametro ' . $this->data['Parametro']['moneda'], 'mensajeBueno');
                $this->redirect(array('action' => 'index'));
            } else
            {
                $this->Session->setFlash('Error al eliminar');
            }
        }
    }
 }
